<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>circle</title>
    <style>
        * {
            padding: 0;
            margin: 0;
        }
    </style>

</head>

<body>
    <canvas id="canvas"></canvas>
</body>

</html>
<script>
    let canvas = document.getElementById("canvas");
    let ctx = canvas.getContext('2d');

    draw(220, 10, 30);

    function draw(w, r, percent) {
        canvas.width = w * 1.5;
        canvas.height = w * 1.5;
        canvas.style.width = w + 'px';
        canvas.style.height = w + 'px';
        //以上为了清晰

        render(w/1.5, r/1.5, percent);
    }

    function render(w, r, percent) {
        ctx.clearRect(0, 0, canvas.width, canvas.height);
        ctx.translate(0.5,0.5)
        ctx.save();
        ctx.beginPath();
        ctx.lineWidth = r;
        ctx.arc(w, w, w - r / 2, -Math.PI, 0);
        ctx.stroke();
        ctx.restore();

        //绘制数字
        ctx.save();
        ctx.translate(w, w);
        var nums = [10, 5, 0];
        ctx.font = '18px Arial';
        ctx.textAlign = 'center';
        ctx.textBaseLine = 'middle';
        nums.forEach((item, index) => {
            var rad = -Math.PI / 2 * index;
            ctx.save()
            ctx.textAlign = 'center'
            ctx.textBaseline = 'middle'
            var x = Math.cos(rad) * 160/1.5,
                y = Math.sin(rad) * 160/1.5;
            ctx.fillText(item, x, y);
            ctx.restore()
        })
        ctx.restore();

        //绘制刻度线
        ctx.save();
        ctx.translate(w, w);

        for (let i = 0; i <= 30; i++) {
            let rad = Math.PI / 30 * i + Math.PI;
            let x = Math.cos(rad) * 200/1.5; // 外半径200
            let y = Math.sin(rad) * 200/1.5;
            ctx.beginPath();
            ctx.moveTo(x, y);
            if (i % 15 == 0) {
                ctx.lineWidth = 4
                let x2 = Math.cos(rad) * 180/1.5; // 内半径190
                let y2 = Math.sin(rad) * 180/1.5;
                ctx.lineTo(x2, y2);
            } else {
                ctx.lineWidth = 1
                let x2 = Math.cos(rad) * 190/1.5; // 内半径190
                let y2 = Math.sin(rad) * 190/1.5;
                ctx.lineTo(x2, y2);
            }
            ctx.stroke()
        }
        //小圆
        ctx.beginPath();
        ctx.strokeStyle = '#000';
        ctx.lineWidth = 1;

        let radisSmall = -Math.PI;
        ctx.arc(-w + r / 2, 0, r / 2, 0, Math.PI * 2);
        ctx.stroke();
        ctx.fillStyle = '#fff';
        ctx.fill();

    }
</script>